package com.demo.vueservice.common.util;

import org.springframework.stereotype.Component;

/**
 * 工厂模式
 * 接口返回生成工具
 * @author zhangliangliang
 * @Component 将其添加到Spring容器中
 */
@Component
public class ResultGen {
    private static final String SUCCESS = "success";

    // 成功
    public  ResultObj getSuccessResult(){
        return new ResultObj()
            .setCode(ResultCode.SUCCESS)
            .setMsg(SUCCESS);
    }

    // 成功，携带数据
    public  ResultObj getSuccessResult(Object data){
        return new ResultObj()
            .setCode(ResultCode.SUCCESS)
            .setMsg(SUCCESS)
            .setData(data);
    }

    // 成功，自定义信息，携带数据
    public  ResultObj getSuccessResult(String message,Object data){
        return new ResultObj()
            .setCode(ResultCode.SUCCESS)
            .setMsg(message)
            .setData(data);
    }

    // 失败,附带消息
    public  ResultObj getFailResult(String msg){
        return new ResultObj()
            .setCode(ResultCode.FAIL)
            .setMsg(msg);
    }

    // 失败，自定义消息和数据
    public  ResultObj getFailResult(String msg,Object data){
        return new ResultObj()
            .setCode(ResultCode.FAIL)
            .setMsg(msg)
            .setData(data);
    }
    // 自定义失败体
    public  ResultObj getFailResult(ResultCode code,String msg,Object data){
        return new ResultObj()
            .setCode(code)
            .setMsg(msg)
            .setData(data);
    }

}
